package com.shierke.Ume.ui.adapter.explore

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.shierke.Ume.R
import com.shierke.Ume.ui.activity.explore.ExploreSubjectTalkActivity
import com.shierke.Ume.util.click
import kotlinx.android.synthetic.main.item_search_hot.view.*

/**
 * Create by Ybx
 * on 2020-10-15
 * Desribe:
 */
class SearchHotAdapter : RecyclerView.Adapter<SearchHotAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {


        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_search_hot, null, false)

        return ViewHolder(view)
    }

    override fun getItemCount() = 20

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.onBind(position)
    }


    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        fun onBind(pos: Int) {
            with(itemView) {
                index.text = "${pos + 1}"
                if (pos < 3) {
                    index.setBackgroundResource(R.drawable.bg_search_hot_image_top)
                    index.setTextColor(Color.parseColor("#ffffff"))
                } else {
                    index.setBackgroundResource(R.drawable.bg_search_hot_image_low)
                    index.setTextColor(Color.parseColor("#2C2C2C"))
                }


                rootView.click {
                    ExploreSubjectTalkActivity.startActivity(context)
                }
            }
        }
    }

}